package com.tinytoon.hunghoaqua;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class CursorAdapter extends android.support.v4.widget.CursorAdapter {

	public CursorAdapter(Context context, Cursor c) {
		super(context, c);
	}

	// bind cursor with view
	@Override
	public void bindView(View v, Context context, Cursor c) {
		TextView index = (TextView)v.findViewById(R.id.ID_txt_index);
		index.setText(Integer.toString(c.getPosition() + 1));//index starts from 1
		
		TextView score = (TextView) v.findViewById(R.id.ID_txt_score);
		score.setText(c.getString(2));

		TextView name = (TextView) v.findViewById(R.id.ID_txt_name);
		name.setText(c.getString(1));

	}

	// inflate row view
	@Override
	public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
		LayoutInflater inflater = LayoutInflater.from(arg0);
		return inflater.inflate(R.layout.row_view, arg2, false);
		// below method causes problem
		// return inflater.inflate(R.layout.cusor_row_view, arg2);
	}
}
